﻿using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class Respawn : MonoBehaviour
{
    public static HashSet<Respawn> all = new HashSet<Respawn>();

    private void Awake()
    {
        all.Add(this);
    }

    public static Respawn GetClosest(Vector3 position)
    {
        List<Respawn> gos = all.ToList<Respawn>();
        gos.SortByDistance<Respawn>(position);
        return gos.FirstOrDefault<Respawn>();
    }

    private void OnDestroy()
    {
        all.Remove(this);
    }

    public Vector3 position
    {
        get
        {
            return base.transform.position;
        }
    }
}

